package com.jxLC.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;

public class ConnDB {
	public static Connection createConn(){
		Connection conn=null;
		try {
			 Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			 conn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=Jxlc","sa","");  
		} catch (Exception e) {
            e.printStackTrace();
		}
		return conn;
	}
	
	public static PreparedStatement prepare(Connection conn,String sql){
		PreparedStatement ps=null;
		try {
			ps=conn.prepareStatement(sql);
		} catch (Exception e) {
          e.printStackTrace();
		}
		return ps;
	}
	
	 public static void close(ResultSet rs){
	    	try {
	    		if(rs!=null){
				rs.close();
				rs=null;
	    		}
			} catch (Exception e) {
	           e.printStackTrace();
			}
	    	
	    }
	 
	 public static void close(Statement st){
	    	try {
	    		if(st!=null){
				st.close();
				st=null;
	    	}
			} catch (Exception e) {
	           e.printStackTrace();
			}
	    	
	    }
	   
    public static void close(Connection conn){
    	try {
    		if(conn!=null){
			conn.close();
			conn=null;
    		}
		} catch (Exception e) {
           e.printStackTrace();
		}
    	
    }
   
}
